<?php
defined('BASEPATH') OR exit('No direct script access allowed');
//系统参数管理
class Config extends MY_Controller {
	public function __construct(){
		parent::__construct();
		$this->sess_checked();
		$this->menuauth();
	}
	public function syslists(){
		$data=array();
		$data['sysos']=PHP_OS;//操作系统
		$data['sysosico']=$_SERVER["SERVER_SOFTWARE"]; //运行环境
		$data['sysversion']=PHP_VERSION;//获取PHP服务器版本
		$data['sysname']=$_SERVER['SERVER_NAME'];//主机名
		$data['prot']=$_SERVER['SERVER_PORT'];//端口
		$data['document_root']=$_SERVER["DOCUMENT_ROOT"];//网站文档目录
		$data['http_user_agent']=substr($_SERVER['HTTP_USER_AGENT'], 0, 40);//浏览器信息
		$data['upload_max_filesize']=ini_get('upload_max_filesize');//上传附件限制
		$data['max_execution_time']=ini_get('max_execution_time');//执行时间限制
		$data['time']=date("Y年n月j日 H:i:s");//服务器时间
		$data['server_name']=$_SERVER['SERVER_NAME'].'/'.gethostbyname($_SERVER['SERVER_NAME']);//服务器域名/IP
		$data['get_client_ip']=$_SERVER['REMOTE_ADDR'];//用户的IP地址
		$data['space']=round((disk_free_space(".")/(1024*1024)),2).'M';//剩余空间
		//mysql
		$data['mysqlversion']=$this->db->version();
		$data['phpversion']=PHP_VERSION;
		$this->assign('list',$data);
		$this->display('config/index.html');
	}
	//参数配置
	public function baselists(){
		if(isset($_POST['ajaxs'])){
			$msg='';
			$data=form_ajaxs($_POST['formjquery']);
			$safeconfig=$this->configedit($data,'safeconfig');
			if(!$safeconfig){
				$msg.='安全配置修改失败,';
			}
			$baseconfig=$this->configedit($data,'baseconfig');
			if(!$baseconfig){
				$msg.='基础配置修改失败,';
			}
			if($data['is_upload_http']==0){
				$data['upload_http']=$this->_URL;
			}
			$upconfig=$this->configedit($data,'upconfig');
			if(!$upconfig){
				$msg.='上传配置修改失败;';
			}
			if($msg!=''){
				ajax_return(0,$msg);
			}else{
				ajax_return(1,'提交成功');
			}
			
		}
		$this->display('config/baselists.html');
	}
	//公共修改配置文件
	private function configedit($data,$filename){
		$config=getFileConfig($filename);
		foreach ($config as $key => $value){
			if(isset($data[$key])){
				$config[$key]=$data[$key];
			}
		}
		if($filename=='upconfig'){
			
		}
		if(setFileConfig($filename,$config)){
			$this->adminuserRecord_m->add(2,1,$filename.'配置文件修改');
			return true;
		}else{
			$this->adminuserRecord_m->add(2,2,$filename.'配置文件修改');
			return false;
		}
	}

}
